﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 设计模式.备忘录模式
{
    public class MementoPatternDemo
    {
        public static void Test()
        {
            Originator originator = new Originator();
            CareTaker careTaker = new CareTaker();
            originator.State=("State #1");
            originator.State=("State #2");
            careTaker.Add(originator.SaveStateToMemento());
            originator.State=("State #3");
            careTaker.Add(originator.SaveStateToMemento());
            originator.State=("State #4");

            Console.WriteLine("Current State: " + originator.State);
            originator.GetStateFromMemento(careTaker[0]);
            Console.WriteLine("First saved State: " + originator.State);
            originator.GetStateFromMemento(careTaker[1]);
            Console.WriteLine("Second saved State: " + originator.State);
        }
    }
}
